/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.srcptit.javatrainning.duongnt.b1;

/**
 *
 * @author ThuyDuong
 */
public class Bai7Muc1Co5den7chuso {
    public static boolean ngto(long a) {
        if(a<=1) return false;
        for (int i = 2; i <= Math.sqrt(a); i++) 
        if (a % i == 0)
         return false;
        return true;}
    public static boolean thuannghich(long a) {
        long m= a,dao=0;
        while(m>0)
        {
            dao=dao*10+m%10;
            m=m/10;
        }
        if(dao==a)
            return true;
        return false;}
        
    public static long tong(long n){
        long t =0;
        while(n!=0){
            t+=n%10;
            n/=10;
        }
        return t;//nhưng ham tong D khong dung toi...D chi dung de ktra tong co là fibo hay k thoi
    }
     public static boolean kTraFibo(long n){
         long tmp = tong(n);
         long f,f1=0,f2=1;
         while(true){
             f = f1+f2;
             f1 = f2;
             f2 = f;
             if(f==tmp) return true;
             else if(f>tmp) return false;
         }
     }
     public static void main(String[] args) {
         long i;
         for(i = 10000; i < 100000; i++)
          {
           if(ngto(i) && kTraFibo(i)&&thuannghich(i))
               System.out.println(i+"   ");}
     }
        
        

}
